#include "loginwidget.h"
#include "ui_mainwindow.h"

QString ASSETPATH ("C:\\Users\\Administrator\\Desktop\\res");



LoginWidget::LoginWidget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::BG)
{
    ui->setupUi(this);


    font = new QFont();
    font->setPointSize(16);

    this->resize(320,420);
    // this->move(10,10);
    // this->setFixedWidth(300);
    this->layout = new QVBoxLayout(this);

    // this->setStyleSheet(
    //     "QWidget{"
    //     "   background-color:rgb(200, 200, 220);"
    //     "}"
    //     );



    iconLabel =  new QLabel(this);
    accountLineEdit = new QLineEdit("",this);
    passwordLineEdit = new QLineEdit("",this);
    loginPushButton = new QPushButton("Login",this);
    // loginPushButton->setEnabled(false);



    iconLabel->resize(100,200);
    QPixmap headIcon(ASSETPATH +"\\qq.png");
    headIcon = headIcon.scaled(100,100,Qt::KeepAspectRatio,Qt::SmoothTransformation);
    iconLabel->setPixmap(headIcon);
    iconLabel->setAlignment(Qt::AlignCenter);
    iconLabel->setStyleSheet(
        "QLabel{"
        "   background:white;"
        "   border-radius:50px;"
        "}");
    iconLabel->setFixedHeight(100);





    accountLineEdit->setAlignment(Qt::AlignCenter);
    accountLineEdit->setFont(*font);
    QLabel *accountIconLabel = new QLabel(accountLineEdit);
    QPixmap accountIconPixmap(ASSETPATH + "\\Icons\\512x512px\\User512x512.png");
    accountIconPixmap = accountIconPixmap.scaled(40,40,Qt::KeepAspectRatio,Qt::SmoothTransformation);
    accountIconLabel->setPixmap(accountIconPixmap);
    accountIconLabel->move(5,5);
    accountIconLabel->setStyleSheet(
        "QLabel{"
        "   background-color:rgba(100,100,100,0.3);"
        "   border-radius:10px;"
        "}"
        );


    passwordLineEdit->setAlignment(Qt::AlignCenter);
    passwordLineEdit->setFont(*font);
    passwordLineEdit->setEchoMode((QLineEdit::Password));
    QLabel *passwordIconLabel = new QLabel(passwordLineEdit);
    QPixmap passwordIconPixmap(ASSETPATH+ "\\Icons\\512x512px\\Key512x512.png");
    passwordIconPixmap = passwordIconPixmap.scaled(40,40,Qt::KeepAspectRatio,Qt::SmoothTransformation);
    passwordIconLabel->setPixmap(passwordIconPixmap);
    // passwordIconLabel->resize(40,40);
    passwordIconLabel->move(5,5);
    passwordIconLabel->setStyleSheet(
        "QLabel{"
        "   background-color:rgba(100,100,100,0.3);"
        "   border-radius:10px;"
        "}"
        );

    loginPushButton->setFont(*font);


    // QSpacerItem *verticalSpacer = new QSpacerItem(20,40,QSizePolicy::Minimum,QSizePolicy::Expanding);
    // layout->addItem(verticalSpacer);



    layout->addWidget(iconLabel);
    layout->addWidget(accountLineEdit);
    layout->addWidget(passwordLineEdit);
    layout->addWidget(loginPushButton);



    accountLineEdit->setStyleSheet(
        "QLineEdit{"
        "   border-radius:10px;"
        "   background-color:rgba(255,255,255,200);"
        "   padding:10px;"
        "}"
        );
    passwordLineEdit->setStyleSheet(
        "QLineEdit{"
        "   border-radius:10px;"
        "   background-color:rgba(255,255,255,200);"
        "   padding:10px;"
        "}"
        );

    loginPushButton->setStyleSheet(
        "QPushButton{"
        "   border-radius:10px;"
        "   padding:20px;"
        "   background-color:rgb(170, 214, 255);"
        "}"
        "QPushButton:pressed {"
        "    background: rgb(120, 140, 255);"
        "}"
        "QPushButton:hover {"
        "    background: rgb(120, 140, 255);"
        "}"
        );



    exitPushButton = new QPushButton("",this);
    connect(exitPushButton,&QPushButton::clicked,this,&this->ExitApp);
    exitPushButton->resize(30,30);

    QPixmap exitIcon(ASSETPATH + "\\Icons\\512x512px\\X512x512.png");
    exitPushButton->setIcon(exitIcon);
    exitPushButton->setIconSize(QSize(20,20));
    exitPushButton->move(285,5);

    exitPushButton->setStyleSheet(
        "QPushButton {"
        "    border: none;"
        "    border-radius:10px;"
        "    background: transparent;"
        "    padding: 0px;"
        "    color:white;"
        "}"
        "QPushButton:pressed {"
        "    background: rgba(255, 100, 100, 0.9);"
        "}"
        "QPushButton:hover {"
        "    background: rgba(220, 50, 50, 0.8);"
        "}"
        );

    AddShadow(iconLabel);
    AddShadow(accountLineEdit);
    AddShadow(passwordLineEdit);
    AddShadow(loginPushButton);
}


LoginWidget::~LoginWidget()
{
    delete ui;
}

void LoginWidget::ExitApp(){

    qDebug()<<"exit";
    QApplication::quit();
}
void LoginWidget::Login()
{
    qDebug()<<"Login";
}

void LoginWidget::AddShadow(QWidget *qWidget)
{
    shadow = new QGraphicsDropShadowEffect(qWidget);
    shadow->setColor(QColor(0, 0, 0, 100));
    shadow->setBlurRadius(30);
    shadow->setOffset(5, 5);
    qWidget->setGraphicsEffect(shadow);
}
